//
//  PaperItemChoiceOptionCell.swift
//  Exam-iOS
//
//  Created by 李胜锋 on 2018/3/9.
//  Copyright © 2018年 李胜锋. All rights reserved.
//

import Foundation
import UIKit

//问题答案选项
class PaperItemChoiceOptionCell: UITableViewCell {
    
    var indexLabel:UILabel!
    var optionLabel:UILabel!
    
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setup()
    }
    
    public func set(id: String?, desc: String?, isSelect:Bool) {
        if id == "T" {
            indexLabel.text = "A"
        }
        else if id == "F" {
            indexLabel.text = "B"
        }
        else {
            indexLabel.text = id
        }
        optionLabel.text = desc
        status = isSelect ? .choise : .nomal
    }
    
    func setup() {
        
        self.backgroundColor = .clear
        
        indexLabel = UILabel()
        indexLabel.clipsToBounds = true
        indexLabel.layer.cornerRadius = 13
        indexLabel.textAlignment = .center
        indexLabel.font = UIFont.systemFont(ofSize: 14)
        
        
        contentView.addSubview(indexLabel)
        
        indexLabel.snp.makeConstraints { (make) in
            make.top.equalTo(7)
            make.leading.equalTo(12)
            make.height.width.equalTo(26)
        }
        
        
        optionLabel = UILabel()
        optionLabel.numberOfLines = 0
        optionLabel.font = UIFont.systemFont(ofSize: 14)
        contentView.addSubview(optionLabel)
        
        optionLabel.snp.makeConstraints { (make) in
            make.edges.equalTo(UIEdgeInsetsMake(12, 47, 12, 20))
        }
        
        status = .nomal
    }
    
    var status:PaperItemOptionStatus = .nomal
    {
        didSet {
            switch status {
            case .choise:
                indexLabel.layer.borderColor = UIColor.clear.cgColor
                indexLabel.layer.borderWidth = 0
                indexLabel.backgroundColor = k_themeColor
                indexLabel.textColor = UIColor.white
            default:
                indexLabel.layer.borderColor = UIColor.black.cgColor
                indexLabel.layer.borderWidth = 0.5
                indexLabel.backgroundColor = UIColor.clear
                indexLabel.textColor = UIColor.black
            }
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
